package com.hnkywl.sts.action.zjgl;

import com.hnkywl.sts.entity.sfgl.Sfk;
import com.hnkywl.sts.entity.sys.Gncz;
import com.hnkywl.sts.entity.zjgl.Bzj;
import com.hnkywl.sts.entity.zjgl.Xyz;
import com.hnkywl.sts.service.organ.KhhService;
import com.hnkywl.sts.service.sfgl.FkshService;
import com.hnkywl.sts.service.sfgl.SkshService;
import com.hnkywl.sts.service.sys.GnczService;
import com.hnkywl.sts.service.zjgl.BzjService;
import com.hnkywl.sts.service.zjgl.XyzService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 说明：
 * 包:        com.hnkywl.sts.action.sfgl
 * 类描述:    岗位Action类
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 */
@Namespace("/zjgl/bzj")
public class BzjAction extends SimpleActionSupport {
    private BzjService bzjService;
    private int page;
    //分页组件 页面大小
    private int rows = 10;
    private Long bzjId;
    private Bzj bzj;
    private Sfk bzjSk;
    private SkshService skshService;
    private String sfkBm;
    private Long gsId;
    private Date createDate;
    private String khMc;
    private String hth;
    //功能操作
    private List<Gncz> gnczList;
    private GnczService gnczService;

    @Action("bzj")
    public String bzj() {
        gnczList = gnczService.findGnczByJsAndUrl(request.getServletPath());
        return SUCCESS;
    }

    //保证金分页显示
    @Action("bzjList")
    public void bzjList() {
        this.renderJson(this.bzjService.findAllBzj(gsId, khMc, hth, createDate, page, rows));
    }

    @Actions({@Action("bzj_content"), @Action("bzj_zj_content")})
    public String bzjContent() {
        //进入update页面
        if (bzjId != null) {
            bzj = bzjService.findBzjDetail(bzjId);

        } else {
            bzj = new Bzj();
        }
        return SUCCESS;
    }

    @Action("bzjQueryByHtid")
    public void bzjquery() {
        this.renderJson(this.bzjService.bzjqueryByHtid(bzjId));
    }

    /**
     * 增加保证金
     */
    @Action("add_bzj")
    public void addBzj() {
        try {
            this.bzjService.saveBzj(bzj, false);
            renderText("{\"statusCode\":\"200\", \"message\":\"添加保证金！\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 追加保证金
     */
    @Action("zj_bzj")
    public void zjBzj() {
        try {
            this.bzjService.saveBzj(bzj, true);
            renderText("{\"statusCode\":\"200\", \"message\":\"追加保证金！\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("update_bzj")
    public void updateXyz() {
        try {
            this.bzjService.updateBzj(bzj);
            renderText("{\"statusCode\":\"200\",\"message\":\"修改保证金成功！\", \"operationType\":\"update\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("delete_bzj")
    public void deleteXyz() {
        try {
            this.bzjService.deleteBzj(bzjId);
            renderText("{\"statusCode\":\"200\", \"message\":\"删除保证金成功！\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    //锁定
    @Action("qr_bzj")
    public void qrBzj() {
        try {
            this.bzjService.qrBzj(bzjId);
            renderText("{\"statusCode\":\"200\", \"message\":\"锁定保证金成功！\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    // 解锁
    @Action("hz_bzj")
    public void hzBzj() {
        try {
            this.bzjService.hzBzj(bzjId);
            renderText("{\"statusCode\":\"200\", \"message\":\"解锁保证金成功！\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }


    @Action("bzj_sk_detail")
    public String ejzhmxFkmxDetail() {
//        bzjSk = skshService.findSfkByBm(sfkBm);
        bzj = this.bzjService.findBzjDetail(bzjId);
        return SUCCESS;
    }


    @Autowired
    public void setBzjService(BzjService bzjService) {
        this.bzjService = bzjService;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public Long getBzjId() {
        return bzjId;
    }

    public void setBzjId(Long bzjId) {
        this.bzjId = bzjId;
    }

    public Bzj getBzj() {
        return bzj;
    }

    public void setBzj(Bzj bzj) {
        this.bzj = bzj;
    }

    public Sfk getBzjSk() {
        return bzjSk;
    }

    public void setBzjSk(Sfk bzjSk) {
        this.bzjSk = bzjSk;
    }

    public String getSfkBm() {
        return sfkBm;
    }

    public void setSfkBm(String sfkBm) {
        this.sfkBm = sfkBm;
    }

    public Long getGsId() {
        return gsId;
    }

    public void setGsId(Long gsId) {
        this.gsId = gsId;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getKhMc() {
        return khMc;
    }

    public void setKhMc(String khMc) {
        this.khMc = khMc;
    }

    public String getHth() {
        return hth;
    }

    public void setHth(String hth) {
        this.hth = hth;
    }

    public List<Gncz> getGnczList() {
        return gnczList;
    }

    public void setGnczList(List<Gncz> gnczList) {
        this.gnczList = gnczList;
    }

    @Autowired
    public void setSkshService(SkshService skshService) {
        this.skshService = skshService;
    }

    @Autowired
    public void setGnczService(GnczService gnczService) {
        this.gnczService = gnczService;
    }
}
